package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ Auther: o2o-rd-0008
 * @ Date:   2020/11/16 11:13
 * @ Param:  ${PARAM}
 * @ Description:
 */
public class BodyHeightQueue {


    public static void main(String[] args) {
        int[][] people = new int[][]{{7, 0}, {4, 4}, {7, 1}, {5, 0}, {6, 1}, {5, 2}, {6, 0}, {3, 2}, {}};

//        reconstructQueue(people);
        int[] nums = new int[]{0, 1, 0, 3, 12};
//        movezero(nums);


//        int[] ints = searchRange(nums, 0);
//        System.out.println(ints[0]+","+ints[1]);

        System.out.println(lengthOfLongestSubstring("dvdf"));
    }


    /**
     * 假设有打乱顺序的一群人站成一个队列。 每个人由一个整数对(h, k)表示，其中h是这个人的身高，k是排在这个人前面且身高大于或等于h的人数。 编写一个算法来重建这个队列。
     * <p>
     * 注意：
     * 总人数少于1100人。
     * <p>
     * 示例
     * <p>
     * 输入:
     * [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
     * <p>
     * 输出:
     * [[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
     *
     * @param people
     * @return
     */

    public static int[][] reconstructQueue(int[][] people) {
        int[][] peo = Arrays.stream(people).sorted((a, b) -> b[0] == a[0] ? Integer.compare(a[1], b[1]) : Integer.compare(b[0], a[0]))
                .toArray(int[][]::new);
        List<int[]> list = new ArrayList<>();
        for (int[] a : peo) {
            list.add(a[1], a);
        }

//        for (int i =0;i<list.size();i++){
//            for (int j=0;j<list.get(i).length;j++){
//                System.out.println(list.get(i)[j]);
//            }
//        }

//        return list.toArray(int[][]::new);
        return null;

        /*int[][] ints = Arrays.stream(people).sorted(
                (a, b) -> a[0] == b[0] ? Integer.compare(a[1], b[1]) : Integer.compare(b[0], a[0])).toArray(int[][]::new
        );

        for (int i =0;i<ints.length;i++){
            System.out.println(people[i][0]+":"+people[i][1]);
        }
        return null;*/
    }


    public static void movezero(int[] nums) {
        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0; i < nums.length; i++) {
            list.add(nums[i]);
        }

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == 0) {
                list.add(list.size(), 0);
                list.remove(i);
            }
        }

//        nums = list;

    }


    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {

        return null;
    }

    public static int[] searchRange(int[] nums, int target) {

        int[] res = new int[]{-1, -1};

        res[0] = binaryArr(nums, target, true);
        res[1] = binaryArr(nums, target, false);

        return res;
    }

    public static int binaryArr(int[] num, int target, boolean flag) {
        int res = -1;

        if (flag) {
            for (int i = 0; i < num.length; i++) {
                if (num[i] == target) {
                    res = i;
                    break;
                }
            }
        } else {
            for (int i = num.length - 1; i >= 0; i--) {
                if (num[i] == target) {
                    res = i;
                    break;
                }
            }
        }

        return res;
    }

    public static int lengthOfLongestSubstring(String s) {
        int res = 0;
        if (s.length() == 1) {
            return 1;
        }

        List list = new ArrayList();

        for (int i = 0; i < s.length(); i++) {
            if (!list.contains(s.charAt(i))) {
                list.add(s.charAt(i));
                if (list.size() == s.length()) {
                    return list.size();
                }
            } else {
                if (list.size() > res) {
                    res = list.size();
                    list.clear();
                    i = i - 2;
                }
            }
        }


        return res;
    }


}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}